//
//  ViewController.m
//  UI02_homework02
//
//  Created by aaaaaa on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "Animation.h"
#import "CostomUISlider.h"

@interface ViewController ()

@end

@implementation ViewController


- (void)dealloc
{
    [_backgroundImageView release];
    [_array release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createInterface];
    [self createSlider];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)createInterface{
    UIImage *backgroundImage = [UIImage imageNamed:@"BackGround.png"];
    self.backgroundImageView= [[UIImageView alloc] initWithImage:backgroundImage];
    self.backgroundImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:self.backgroundImageView];
    [self.backgroundImageView release];
    
    self.array = [NSMutableArray arrayWithCapacity:10];
    
    Animation *flower = [Animation createFlowerWithFrame:CGRectMake(70, 100, 73, 74)];
    [self.array addObject:flower];
    [self.view addSubview:flower];
    
    
    Animation *gua = [Animation createGuaWithFrame:CGRectMake(250, 80, 106, 98)];
    [self.array addObject:gua];
    [self.view addSubview:gua];
    
    Animation *plants = [Animation createPlantsWithFrame:CGRectMake(60, 340, 106, 107)];
    [self.array addObject:plants];
    [self.view addSubview:plants];
    
    Animation *zombie = [Animation createZombieWithFrame:CGRectMake(200, 150, 164, 144)];
    [self.array addObject:zombie];
    [self.view addSubview:zombie];
    
    Animation *bZombie1 = [Animation createBZombieWithFrame:CGRectMake(200, 300, 205, 163)];
    [self.array addObject:bZombie1];
    [self.view addSubview:bZombie1];
    
    Animation *bZimbie2 = [Animation createBZombieWithFrame:CGRectMake(200, 420, 205, 163)];
    [self.array addObject:bZimbie2];
    [self.view addSubview:bZimbie2];
    
    
}

- (void)createSlider{
    CostomUISlider *slider = [[CostomUISlider alloc] initWithFrame:CGRectMake(100, 500, 250, 50)];
    [self.view addSubview:slider];
    [slider release];
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
}

- (void)sliderAction:(CostomUISlider *)slider{
    
    for (int i = 0; i < self.array.count; i++) {
        Animation *animation = self.array[i];
        [animation stopAnimating];
        animation.animationDuration =slider.maximumValue - slider.value ;
        [animation startAnimating];
    }

    

}







@end
